/**
 * 隐私数据，支持修改和查看
 */
Rsd.define('Rsd.form.Privacy', {
    extend: 'Rsd.form.Input',
    xtype: 'privacy',
    margin: '2 0 2 0',
    //    height: 25,
    //    width: 80,
    inputType: 'text',
    //ctrlCls: 'x-control-privacy',
    handler: null,
    /**
     * @description 数据查看器配置
     * {
        style:null,
        text:'[查 看]',
        handler:''
       }
     */
    //viewor:null,
    /**
     * 代替显示的文字内容
     */
    value: '隐私数据已隐藏显示',
    /**
     * 
     * @param {*} config 
     */
    constructor: function constructor(config) {
        config = config || {};
        this.apply(config);
        this.readonly = true;
        this.viewor = this.viewor || {};
    },
    /**
     * 初始化 仅创建对象，并未渲染dom结构
     */
    initComponentEx: function initComponentEx() {
        this.callParent();

        var me = this;
        var viewor = me.viewor || {};
        if (me.readable) {
            var btn = document.createElement('a');
            viewor.element = btn;

            btn.id = this.id + '__viewer';
            btn.innerHTML = viewor.text || "[查 看]";
            btn.title = viewor.tip || viewor.title || '查看数据';
            btn.style.marginRight = "8px";
            btn.style.marginLeft = "10px";
            btn.style.float = "right";
            btn.style.position = "relative";
            btn.style.zIndex = 9999;
            btn.style.lineHeight = me.height + 'px';
            btn.href = "javascript:void(0);"

            me.ctrl.element.ondblclick = btn.onclick = function (event) {
                if (viewor.handler || viewor.fn) {
                    me.funApplyByIOC(viewor.handler || viewor.fn, [me, event]);
                }
            }
            me.setElStyle(btn, viewor.style || {});
        }
        if (me.editable) {
            var btnUpdate = document.createElement('a');
            viewor.updateElement = btnUpdate;

            btnUpdate.id = this.id + '__update';
            btnUpdate.innerHTML = viewor.updateText || "[修改]";
            btnUpdate.title = viewor.updateTip || viewor.updateTitle || '修改数据';
            btnUpdate.style.marginRight = "8px";
            btnUpdate.style.marginLeft = "0px";
            btnUpdate.style.float = "right";
            btnUpdate.style.position = "relative";
            btnUpdate.style.zIndex = 9999;
            btnUpdate.style.lineHeight = me.height + 'px';
            btnUpdate.href = "javascript:void(0);"
            btnUpdate.onclick = function (event) {
                if (viewor.updateHandler || viewor.updateFn) {
                    me.funApplyByIOC(viewor.updateHandler || viewor.updateFn, [me, event]);
                }
                me.readonly = false;
                me.setValue('');
                //me.setValue("");
            }
        }

    },
    /**
     * 
     */
    onAfterRender: function onAfterRender() {
        this.callParent();

        if (this.viewor && this.viewor.element) {
            this.dom.appendChild(this.viewor.element);
        }

        if (this.viewor && this.viewor.updateElement) {
            this.dom.appendChild(this.viewor.updateElement);
        }
    }

}, function (type) {

    var _vieworGetter = function () {

        return this.___viewor;
    };

    var _vieworSetter = function (value) {

        this.___viewor = Rsd.apply({ style: null, text: '[查 看]', handler: '' }, value || {});
    }

    this.defineProperty(type, "viewor", _vieworGetter, _vieworSetter, false);
});

